package com.apartment.own.controller;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnResHouseContract;
import com.apartment.own.service.IOwnResHouseContractService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/houseContract")
public class OwnResHouseContractController extends BaseController
{
    @Autowired
    private IOwnResHouseContractService ownResHouseContractService;

    /**
     * 查询合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租列表
     */
    @PreAuthorize("@ss.hasPermi('own:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnResHouseContract ownResHouseContract)
    {
        startPage();
        List<OwnResHouseContract> list = ownResHouseContractService.selectOwnResHouseContractList(ownResHouseContract);
        return getDataTable(list);
    }

    /**
     * 导出合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租列表
     */
    @PreAuthorize("@ss.hasPermi('own:contract:export')")
    @Log(title = "合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnResHouseContract ownResHouseContract)
    {
        List<OwnResHouseContract> list = ownResHouseContractService.selectOwnResHouseContractList(ownResHouseContract);
        ExcelUtil<OwnResHouseContract> util = new ExcelUtil<OwnResHouseContract>(OwnResHouseContract.class);
        return util.exportExcel(list, "contract");
    }

    /**
     * 获取合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ownResHouseContractService.selectOwnResHouseContractById(id));
    }

    /**
     * 新增合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     */
    @PreAuthorize("@ss.hasPermi('own:contract:add')")
    @Log(title = "合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnResHouseContract ownResHouseContract)
    {
        return toAjax(ownResHouseContractService.insertOwnResHouseContract(ownResHouseContract));
    }

    /**
     * 修改合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     */
    @PreAuthorize("@ss.hasPermi('own:contract:edit')")
    @Log(title = "合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnResHouseContract ownResHouseContract)
    {
        return toAjax(ownResHouseContractService.updateOwnResHouseContract(ownResHouseContract));
    }

    /**
     * 删除合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租
     */
    @PreAuthorize("@ss.hasPermi('own:contract:remove')")
    @Log(title = "合同 ???零散期前后置什么意思   ???租金分界怎么分界 ???免租期怎么免租", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ownResHouseContractService.deleteOwnResHouseContractByIds(ids));
    }

    @GetMapping("/info/{id}")
    @ApiOperation("根据房源id,查询合同id")
    public AjaxResult contractInfoByResId(@PathVariable String id){
        return AjaxResult.success(ownResHouseContractService.contractInfoByResId(id));
    }
}
